package com.projectsexception.festivales;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;

public class MainActivity extends TabActivity {
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab
        
        List<Tab> tabs = getTabs();
        for (Tab tab : tabs) {
            intent = new Intent().setClass(this, tab.getActivityClass());
            spec = tabHost.newTabSpec(tab.getTitle());
            spec.setIndicator(tab.getTitle(), getResources().getDrawable(tab.getIcon()));
            spec.setContent(intent);
            tabHost.addTab(spec);
        }

        tabHost.setCurrentTab(0);
    }
    
    private List<Tab> getTabs() {
        List<Tab> tabs = new ArrayList<Tab>();
        Tab tab = new Tab(TabScheduleActivity.class, getString(R.string.tab_schedule_title), R.drawable.tab_schedule);
        tabs.add(tab);
        tab = new Tab(TabStagesActivity.class, getString(R.string.tab_stages_title), R.drawable.tab_stages);
        tabs.add(tab);
        tab = new Tab(TabNewsActivity.class, getString(R.string.tab_news_title), R.drawable.tab_news);
        tabs.add(tab);        
        tab = new Tab(TabMapsActivity.class, getString(R.string.tab_maps_title), R.drawable.tab_maps);
        tabs.add(tab);
        tab = new Tab(TabInfoActivity.class, getString(R.string.tab_info_title), R.drawable.tab_info);
        tabs.add(tab);
        return tabs;
    }
    
    private class Tab {
        private Class<? extends Activity> activityClass;
        private String title;    
        private int icon;

        public Tab(Class<? extends Activity> activityClass, String title, int icon) {
            this.activityClass = activityClass;
            this.title = title;
            this.icon = icon;
        }

        public String getTitle() {
            return title;
        }

        public int getIcon() {
            return icon;
        }
        
        public Class<? extends Activity> getActivityClass() {
            return activityClass;
        }
    }

}
